﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace Engine2D
{
    public class RendererSettings
    {
        public class Resolution
        {
            public int Width;
            public int Height;
            public Resolution(int width, int height)
            {
                this.Width = width;
                this.Height = height;
            }
        }

        private GraphicsDeviceManager mGraphics;
        private List<Resolution> mResolutions;
        private int mDefaultResolutionIndex;

        public Resolution DefaultResolution { get { return mResolutions[mDefaultResolutionIndex]; } }
        public Resolution CurrentResolution { get { return new Resolution(mGraphics.PreferredBackBufferWidth, mGraphics.PreferredBackBufferHeight); } }
        public List<Resolution> Resolutions { get { return mResolutions; } }

        public RendererSettings(GraphicsDeviceManager graphics)
        {
            mGraphics = graphics;
            SetupResolutions();
        }

        private void SetupResolutions()
        {
            mResolutions = new List<Resolution>();
            mResolutions.Add(new Resolution(640, 480));
            mResolutions.Add(new Resolution(800, 600));
            mResolutions.Add(new Resolution(1024, 768));
            mResolutions.Add(new Resolution(1024, 576));
            mResolutions.Add(new Resolution(1280, 720));
            mResolutions.Add(new Resolution(1920, 1080));
            mDefaultResolutionIndex = 4;
        }

        public void SetResolution(Resolution resolution, bool fullscreen)
        {
            mGraphics.PreferredBackBufferWidth = resolution.Width;
            mGraphics.PreferredBackBufferHeight = resolution.Height;
            mGraphics.IsFullScreen = fullscreen;
            mGraphics.ApplyChanges();
        }
    }
}
